import React from 'react'
import { ChessType, GameStatus } from '../types/enums'
import { BoardC } from './BoardC'

interface StateI {
	chesses: ChessType[]
	gameStatus: GameStatus
	nextColor: ChessType.red | ChessType.black
}

export class GameC extends React.Component<{}, StateI> {
	state: StateI = {
		chesses: [],
		gameStatus: GameStatus.gaming,
		nextColor: ChessType.red,
	}
	componentDidMount(): void {
		this.init()
	}
	/**
	 * 游戏初始化函数
	 */
	init() {
		const arr: ChessType[] = []
		for (let i = 0; i < 9; i++) {
			arr.push(ChessType.none)
		}
		this.setState({
			chesses: arr,
			gameStatus: GameStatus.gaming,
		})
	}
	/**
	 * 处理棋子被点击事件
	 * 如果该函数运行，说明
	 * 1. 游戏没用结束
	 * 2. 点击的位置没用棋子
	 */
	handleClickChess(index: number) {}
	render(): React.ReactNode {
		return (
			<div className="game">
				<BoardC
					chesses={this.state.chesses}
					isGameOver={this.state.gameStatus !== GameStatus.gaming}
					handleClick={this.handleClickChess.bind(this)}
				></BoardC>
			</div>
		)
	}
}
